package xin.yangshuai.zookeeper01.case1;

import org.apache.zookeeper.KeeperException;

import java.io.IOException;

public class DistributeTest {

    public static void main(String[] args) throws InterruptedException, IOException, KeeperException {

        // 启动客户端，连接zookeeper，客户端设置监听
        DistributeClient client = new DistributeClient();
        client.getConnect();
        // 启动服务器1，连接zookeeper
        DistributeServer server1 = new DistributeServer();
        server1.getConnect();
        // 启动服务器2，连接zookeeper
        DistributeServer server2 = new DistributeServer();
        server2.getConnect();
        Thread.sleep(5000);

        // 服务器1上线
        server1.register();
        Thread.sleep(5000);

        // 服务器2上线
        server2.register();
        Thread.sleep(5000);

        // 服务器1下线
        server1.close();
        Thread.sleep(5000);

        // 服务器2下线
        server2.close();

        Thread.sleep(Long.MAX_VALUE);
    }
}
